<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>FMC管理</el-breadcrumb-item>
      <el-breadcrumb-item>FMC脚本</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input v-model="queryInfo.query"
                    class="input-with-select"
                    :clearable="true"
                    placeholder="请输入内容"
                    @clear="getUserList"
                    @keyup.enter.native="getUserList">
            <el-button slot="append"
                       icon="el-icon-search"
                       @click="getUserList"></el-button>
          </el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary"
                     @click="addDialogVisible = true">添加脚本</el-button>
        </el-col>
      </el-row>

      <!--  用户列表区域-->
      <el-table :data="tableData"
                :stripe="true"
                :border="true"
                style="width: 100%">
        <el-table-column type="index"
                         width="50">
        </el-table-column>
        <el-table-column prop="name"
                         label="模块"
                         width="180">
        </el-table-column>
        <el-table-column prop="phone"
                         label="脚本名"
                         width="180">
        </el-table-column>
        <el-table-column label="操作"
                         width="120">
          <template slot-scope="scope">
            <el-button @click="showEditDialog(scope.row.id)"
                       type="text"
                       size="small">编辑</el-button>
            <el-button @click="delconfirm(scope.row.id)"
                       type="text"
                       size="small">删除</el-button>
            <el-button @click="assign(scope.row)"
                       type="text"
                       size="small">执行</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页控件 -->
      <el-pagination @size-change="pagesizeChange"
                     @current-change="currentChange"
                     :current-page="queryInfo.pagenum"
                     :page-sizes="[1, 2, 5, 10]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </el-card>

    <!-- 对话框区域 -->
    <!-- 新增员工对话框区域 -->
    <el-dialog title="新增员工"
               width="35%"
               :visible.sync="addDialogVisible">
      <el-form ref="addFormRef"
               :model="addform"
               label-width="70px">
        <el-form-item label="模块"
                      prop="modename">
          <el-input v-model="addform.modename"
                    width="15px"></el-input>
        </el-form-item>
        <el-form-item label="脚本名"
                      prop="scriptname">
          <el-input v-model="addform.scriptname"></el-input>
        </el-form-item>
        <el-form-item label="脚本文件"
                      prop="file">
          <el-upload action="http://127.0.0.1:8083/api/uploadFile"
                     :on-change="handleChange"
                     :file-list="fileList">
            <el-button size="small"
                       type="primary">点击上传</el-button>
            <div slot="tip"
                 class="el-upload__tip">只能上传jmx文件，且不超过200M</div>
          </el-upload>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 编辑员工对话框区域 -->
    <el-dialog title="编辑员工"
               width="35%"
               :visible.sync="editDialogVisible">
      <el-form ref="editFormRef"
               :model="editform"
               label-width="70px">
        <el-form-item label="模块"
                      prop="modename">
          <el-input v-model="editform.modename"
                    width="15px"
                    disabled></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: 'Script',
  created () {
    this.getScriptList()
  },
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: '',
        pagesize: ''
      },
      addform: {
        modename: '',
        modescript: '',
        file: ''
      },
      editform: {
        modename: '',
        modescript: '',
        file: ''
      },
      addDialogVisible: false,
      editDialogVisible: false
    }
  },
  methods: {
    showEditDialog () {
      this.editDialogVisible = true
    },
    async getScriptList () {
      const { data: res } = await this.$http.get('/pageEmp', {
        params: this.queryInfo
      })
      if (res.code !== 200) {
        this.$message.error(res.message)
      }
      this.tableData = res.data.content
      this.total = res.data.pageInfo.total
    }
  }

}
</script>

<style>
</style>
